<?php session_start();
$login = $_SESSION['login'];
$privilegio = $_SESSION['privilegio'];

require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Privilegio.php');
$forum = $_GET['forum'];
$assunto = $_GET['assunto'];
$topico = $_GET['topico'];
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <link href="/Esquina_da_TI/default.css" rel="stylesheet" type="text/css" media="screen" />
        <script src="/Esquina_da_TI/js/jquery-1.3.2.js" type="text/javascript"></script>
        <script src="/Esquina_da_TI/js/exibirPaginas.js" type="text/javascript"></script>
        <script src="/Esquina_da_TI/js/tituloDinamico.js" type="text/javascript"></script>
        <title><?php echo $topico;?></title>
    </head>
    <body>
        <!--CABEÇALHO-->
        <div id="header">
            <div id="menu">
                <ul id="main">
                    <li><a href="/Esquina_da_TI/index.php"><img src="/Esquina_da_TI/images/home.png" class="menu"  title="Inicio" /><br/><b>Inicio</b></a></li>
                        <li><a href="/Esquina_da_TI/Gui/Forum.php"><img src="/Esquina_da_TI/images/forum.png" class="menu" title="Fórum"/><br/><b>Fórum</b></a></li>
                        <li><a href="javascript:exibirVerNoticia()"><img src="/Esquina_da_TI/images/noticia.png" class="menu" title="Noticia"/><br/><b>Notícias</b></a></li>
                        <li><a href="javascript:exibirVerArtigos()"><img src="/Esquina_da_TI/images/artigo.png" class="menu" title="Artigos"/><br/><b>Artigos</b></a></li>
                        <li><a href="/Esquina_da_TI/Gui/Downloads.php"><img src="/Esquina_da_TI/images/download.png" class="menu" title="Downloads"/><br/><b>Downloads</b></a></li>
                        <li><a href="/Esquina_da_TI/Gui/CadastroUsuario.php"><img src="/Esquina_da_TI/images/Cadastro.png" class="menu" title="Cadastro"/><br/><b>Cadastro</b></a></li>
                        <li><a href="/Esquina_da_TI/Gui/OportunidadeEmprego.php"><img src="/Esquina_da_TI/images/oportunidade.png" class="menu" title="Empregos"/><br/><b>Empregabilidade</b></a></li>
                        <li><a href="javascript:exibirFaleConosco()"><img src="/Esquina_da_TI/images/faleconosco.png" class="menu" title="Fale Conosco"/><br/><b>Fale Conosco</b></a></li>
                        <li><a href="javascript:favoritos()"><img src="/Esquina_da_TI/images/addFavoritos.png" class="menu" title="Add Favoritos"/><br/><b>Favoritos</b></a></li>
                </ul>
            </div>
            <div id="logo">
                <h1><a href="#"><span>Esquina da T.I.</span></a></h1>
                <p>a Tecnologia a seu alcance</p>
            </div>
        </div>
        <div id="wrapper">
            <div id="page">
                <div id="sidebar2" class="sidebar">
                    <?php

                    if (isset ($_SESSION['login'])) {
                        echo " <div id='loginForum'>";
                        echo  "<b><font color =  '#FF7F00'>".$_SESSION['privilegio'] ." >>> </font>". " <font color='#0066ff'>"  . $_SESSION['login']."</font></b></div>";
                        echo " <div id='logoffForum'>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        echo "<a href='MinhaConta.php'><img src='/Esquina_da_TI/images/minhaConta.png'/></a>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        echo "<a href='logoff.php'><img src='/Esquina_da_TI/images/logoff.png'/></a>";
                        echo"<br>";
                        echo "<a href='MinhaConta.php'><b><font color='#0066ff'>Minha Conta </font></b></a>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        echo "<a href='GUI/logoff.php'><b><font color='#0066ff'>Logoff</font></b></a>";
                    }
                    else {
                        echo " <div id='loginForum'>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        echo "<a href='EfetuarLogin.php'><img src='/Esquina_da_TI/images/login.png'/></a><br>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        echo "<a href='EfetuarLogin.php'><b><font color='#0066ff'>Fazer Login</font></b></a><br>";
                        echo "<font color =  '#FF7F00'>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

                        ?>

                    <script language="JavaScript">

                        <!--
                        var d = new Date()
                        var h = d.getHours()

                        if (h < 12)
                            document.write("Bom-dia ! ")
                        else
                            if (h < 18)
                                document.write("Boa-tarde ! ")
                        else
                            document.write("Boa-noite ! ")
                        // -->
                    </script>

                        <?php
                        echo "<b>&nbsp;&nbsp;Visitante</b></font><br>";

                    }

                    echo "</div>";
                    echo "</div>";
                    ?>
                    <br/>
                    <a href='/Esquina_da_TI/Gui/Forum.php'><font style="text-align:left" size="5px" color="Red">Indice dos Foruns</font></a>
                    <font style="text-align:left" size="5px" color="Green">>>></font>
                    <a href='/Esquina_da_TI/Gui/exibirAssuntos.php?forum=<?php echo $forum;?>'><font style="text-align:left" size="5px" color="Red"><?php echo $forum;?></font></a>
                    <font style="text-align:left" size="5px" color="Green">>>></font>
                    <a href='/Esquina_da_TI/Gui/exibirTopicos.php?forum=<? echo $forum;php?>&assunto=<?php echo $assunto;?>'><font style="text-align:left" size="5px" color="Red"><?php echo $assunto;?></font></a>
                    <font style="text-align:left" size="5px" color="Green">>>></font>
                    <a href='/Esquina_da_TI/Gui/exibirTopico.php?forum=<? echo $forum;php?>&assunto=<?php echo $assunto;?>&topico=<?php echo $topico;?>'><font style="text-align:left" size="5px" color="Red"><?php echo $topico;?></font></a>

                    <br/>
                    <a href='/Esquina_da_TI/Gui/responderTopico.php?forum=<? echo $forum;php?>&assunto=<?php echo $assunto;?>&topico=<?php echo $topico;?>'><img src="/Esquina_da_TI/images/responderTopico.jpg"/></a>
                    &nbsp;

                    <!--CONTEUDO DO CENTRO-->
                    <div align="center" style="border:double">
                        <div class="post" align="center">
                            <form name='forum' method='post' action=''>
                                <table class="forum" cellspacing="1" cellpadding="1">
                                    <tr>
                                        <td width='15%' class="head" colspan="2">Autor</td>
                                        <td width='80%' class="head" colspan="2">Mensagem</td>
                                    </tr>
                                    <?php
                                    require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/Gui/Fachada.php');
                                    require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Topico.php');

                                    $fachada = new Fachada();
                                    $topicoAtual = new Topico();

                                    $topicoAtual = $fachada->exibirTopico($topico);
                                    $dataTopico = $topicoAtual->getData();
                                    $tituloTopico = $topicoAtual->getTitulo();
                                    $autorTopico = $topicoAtual->getUsuario();
                                    $textoTopico = $topicoAtual->getTexto();

                                    $usuario = new Usuario();
                                    $usuario = $fachada->localizarUsuario($codigo, $nome, $autorTopico);
                                    $fotoAutor = $usuario->getFoto();
                                    echo "<tr>";
                                    echo "<td class='responder' colspan='2'>". $dataTopico. "</td>";
                                    echo "<td class='responder' colspan='2'>Titulo: <font color='blue'>". $tituloTopico. "</font></td>";
                                    echo "</tr>";
                                    echo "<tr>";
                                    echo "<td class='forum' colspan='2'>". $autorTopico. "<br/><br/>";
                                    echo "<img src='".$fotoAutor."' class='forum'/>";
                                    echo "</td>";

                                    $linhas = explode("\n", $textoTopico);
                                    $tamanhoTexto = count($linhas);

                                    $textoTopico = str_replace("\n", "<br/>", $textoTopico);
                                    $textoTopicoFormatado = formatarTexto($textoTopico);

                                    echo "<td class='responderForum' height='$tamanhoTexto' colspan='2'>".$textoTopicoFormatado."</td>";
                                    echo "</tr>";

                                    echo '<tr><td></td></tr>';




                                    $respostas = $fachada->listarRespostas($topico);


                                    foreach($respostas as $r) {
                                        $dataResposta = $r['data'];
                                        $tituloResposta = $r['titulo'];
                                        $autorResposta = $r['login'];
                                        $textoResposta = $r['texto'];

                                        $user = new Usuario();
                                        $user = $fachada->localizarUsuario($codigo, $nome, $autorResposta);
                                        $fotoAutorResposta = $user->getFoto();

                                        echo "<tr>";
                                        echo "<td class='responder' colspan='2'>". $dataResposta. "</td>";
                                        echo "<td class='responder' colspan='2'>Re: <font color='blue'>". $tituloResposta . "</font></td>";
                                        echo "</tr>";
                                        echo "<tr>";
                                        echo "<td class='forum' colspan='2'>" . $autorResposta  . "<br/><br/>";
                                        echo "<img src='".$fotoAutorResposta."' class='forum'/>";
                                        echo "</td>";

                                        $linhasResposta = explode("\n", $textoResposta);
                                        $tamanhoResposta = count($linhasResposta);

                                        $textoResposta = str_replace("\n", "<br/>", $textoResposta);
                                        $textoRespostaFormatado = formatarTexto($textoResposta);

                                        echo "<td class='resposta' width='80%' height='$tamanhoResposta' colspan='2'>".$textoRespostaFormatado."</td>";
                                        echo "</tr>";

                                    }

                                    function formatarTexto($texto) {
                                        $novoTexto = $texto;
                                        $novoTexto = str_replace(":)", "<img src='/Esquina_da_TI/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":D", "<img src='/Esquina_da_TI/images/smilies/283a16da79f3aa23fe1025c96295f04f.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":(", "<img src='/Esquina_da_TI/images/smilies/9d71f0541cff0a302a0309c5079e8dee.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":-o", "<img src='/Esquina_da_TI/images/smilies/47941865eb7bbc2a777305b46cc059a2.gif' border='0'>", $novoTexto);

                                        $novoTexto = str_replace(":shock:", "<img src='/Esquina_da_TI/images/smilies/385970365b8ed7503b4294502a458efa.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":?:", "<img src='/Esquina_da_TI/images/smilies/0a4d7238daa496a758252d0a2b1a1384.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":8)", "<img src='/Esquina_da_TI/images/smilies/b2eb59423fbf5fa39342041237025880.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":lol:", "<img src='/Esquina_da_TI/images/smilies/97ada74b88049a6d50a6ed40898a03d7.gif' border='0'>", $novoTexto);

                                        $novoTexto = str_replace(":x", "<img src='/Esquina_da_TI/images/smilies/1069449046bcd664c21db15b1dfedaee.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":P", "<img src='/Esquina_da_TI/images/smilies/69934afc394145350659cd7add244ca9.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":oops:", "<img src='/Esquina_da_TI/images/smilies/499fd50bc713bfcdf2ab5a23c00c2d62.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":cry:", "<img src='/Esquina_da_TI/images/smilies/c30b4198e0907b23b8246bdd52aa1c3c.gif' border='0'>", $novoTexto);

                                        $novoTexto = str_replace(":evil:", "<img src='/Esquina_da_TI/images/smilies/2e207fad049d4d292f60607f80f05768.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":twisted:", "<img src='/Esquina_da_TI/images/smilies/908627bbe5e9f6a080977db8c365caff.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":roll:", "<img src='/Esquina_da_TI/images/smilies/2786c5c8e1a8be796fb2f726cca5a0fe.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":wink:", "<img src='/Esquina_da_TI/images/smilies/8a80c6485cd926be453217d59a84a888.gif' border='0'>", $novoTexto);

                                        $novoTexto = str_replace(":!:", "<img src='/Esquina_da_TI/images/smilies/9293feeb0183c67ea1ea8c52f0dbaf8c.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":?", "<img src='/Esquina_da_TI/images/smilies/136dd33cba83140c7ce38db096d05aed.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":idea:", "<img src='/Esquina_da_TI/images/smilies/8f7fb9dd46fb8ef86f81154a4feaada9.gif' border='0'>", $novoTexto);
                                        $novoTexto = str_replace(":arrow:", "<img src='/Esquina_da_TI/images/smilies/d6741711aa045b812616853b5507fd2a.gif' border='0'>", $novoTexto);


                                        return $novoTexto;
                                    }
                                    ?>

                                </table>
                            </form>
                        </div>
                        <a href="exibirTopicos.php?forum=<?php echo $forum?>&assunto=<?php echo $assunto?>"><font color="blue"><<< Voltar</font></a>
                        <br><br>
                    </div>

                </div>
                <!--BARRA DO RODAPÉ-->
                <div style="clear: both;">&nbsp;</div>
            </div>
        </div>

        <!--RODAPÉ-->
        <div id="footer">
            <p class="copyright">&copy;&nbsp;&nbsp;2009 All Rights Reserved &nbsp;&bull;&nbsp; Design by <a href="#">H1 Softwares</a>.</p>
            <p class="link"><a href="#">Privacy Policy</a>&nbsp;&#8226;&nbsp;<a href="#">Terms of Use</a></p>
        </div>
    </body>
</html>
